<?php
require '../../common/initPage.php';
require '../../common/dbcon.php';
require '../../common/func.php';
require '../../common/showTips.php';

session_start();
//拦截未登录
filterLogout();

if(!empty($_GET['dealwitharray'])) {
    if($_GET['action']=='read') {
        $updataMessIsRead="UPDATE usermessage SET gettime =  '".date('Y-m-d H:i:s', time())."' WHERE mid IN (".$_GET['dealwitharray'].")";
        if(upMess($mysqlCon,$updataMessIsRead)){
            $_SESSION['actionMessShowTips']='成功将消息标记为已读';
            $_SESSION['actionMesstipsType']='success';
            //并更新页头的未读消息
            $_SESSION['loginUnReadMessInfo']=queryUnReadMess($mysqlCon,queryBrowseLNewButUnRead,$_SESSION['loginId']);
        }else{
            $_SESSION['actionMessShowTips']='将消息标记为已读失败';
            $_SESSION['actionMesstipsType']='danger';
        }
    }else if ($_GET['action']=='unread'){
        $updataMessIsUnRead='UPDATE usermessage SET gettime = NULL WHERE mid IN ('.$_GET['dealwitharray'].')';
        if(upMess($mysqlCon,$updataMessIsUnRead)){
            $_SESSION['actionMessShowTips']='成功将消息标记为未读';
            $_SESSION['actionMesstipsType']='success';
            //并更新页头的未读消息
            $_SESSION['loginUnReadMessInfo']=queryUnReadMess($mysqlCon,queryBrowseLNewButUnRead,$_SESSION['loginId']);
        }else{
            $_SESSION['actionMessShowTips']='将消息标记为未读失败';
            $_SESSION['actionMesstipsType']='danger';
        }
    }else if ($_GET['action']=='star'){
        if(uplockUser($mysqlCon,updteMessisStar,$_GET['dealwitharray'])){
            $_SESSION['actionMessShowTips']='收藏消息成功';
            $_SESSION['actionMesstipsType']='success';
        }else{
            $_SESSION['actionMessShowTips']='收藏消息失败';
            $_SESSION['actionMesstipsType']='danger';
        }
    }else if ($_GET['action']=='unstar'){
        if(uplockUser($mysqlCon,updteMessisStar,$_GET['dealwitharray'])){
            $_SESSION['actionMessShowTips']='取消收藏消息成功';
            $_SESSION['actionMesstipsType']='success';
        }else{
            $_SESSION['actionMessShowTips']='取消收藏消息失败';
            $_SESSION['actionMesstipsType']='danger';
        }
    }else if($_GET['action']=='move'){
        $moveMessToTrash="UPDATE usermessage SET messstate = 2 , gettime = '".date('Y-m-d H:i:s', time())."' WHERE mid IN (".$_GET['dealwitharray'].")";
        if(upMess($mysqlCon,$moveMessToTrash)){
            $_SESSION['actionMessShowTips']='已成功将消息删除，一个月内可从回收站复原';
            $_SESSION['actionMesstipsType']='success';
        }else{
            $_SESSION['actionMessShowTips']='消息删除失败';
            $_SESSION['actionMesstipsType']='danger';
        }
    }else if($_GET['action']=='del'){
        $delMess="DELETE FROM usermessage WHERE mid IN (".$_GET['dealwitharray'].")";
        if($_GET['deltype']=='trash'){
            if(upMess($mysqlCon,$delMess)){
                $_SESSION['actionMessShowTips']='清除消息成功';
                $_SESSION['actionMesstipsType']='success';
            }else{
                $_SESSION['actionMessShowTips']='清除消息失败';
                $_SESSION['actionMesstipsType']='danger';
            }
        }else if ($_GET['deltype']=='save'){
            if(upMess($mysqlCon,$delMess)){
                $_SESSION['actionMessShowTips']='删除草稿成功';
                $_SESSION['actionMesstipsType']='success';
            }else{
                $_SESSION['actionMessShowTips']='删除草稿失败';
                $_SESSION['actionMesstipsType']='danger';
            }
        }
    }else if($_GET['action']=='back'){
        $backMess="UPDATE usermessage SET messstate = 0  WHERE mid IN (".$_GET['dealwitharray'].")";
        if(upMess($mysqlCon,$backMess)){
            $_SESSION['actionMessShowTips']='已成功将消息复原至信箱';
            $_SESSION['actionMesstipsType']='success';
        }else{
            $_SESSION['actionMessShowTips']='将消息复原至信箱失败';
            $_SESSION['actionMesstipsType']='danger';
        }
    }
}
//删除最后一页最后一条数据时的页码处理
$rows=$_GET['rows'];
$rempagenow=$_SESSION['messagePageNow'];
$lastpage=$_GET['lastpage'];
if(($rows-1)%3==0 && $rempagenow==$lastpage) $rempagenow-=1;

header('location:./message.php?&show=true&pagenow='.$rempagenow.'&searchvalue='.$_SESSION['messageSearchvalue'].'&check='.$_SESSION['checkCate'].'&filter='.$_SESSION['filter']);
